/*
*	@file
*	@author  Thomas Kroes <t.kroes at tudelft.nl>
*	@version 1.0
*	
*	@section LICENSE
*	
*	Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*	
*	Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*	Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*	Neither the name of the TU Delft nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
*	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*	
*	Part of the SSAO code is based on the tutorial by Michael Belanec: http://www.belanecbn.sk/opengl_tutorialy/index.php?id=30
*	The bloom filter code is based on code snippets from chapter 8 in "iPhone 3D Programming: http://ofps.oreilly.com/titles/9780596804824/chadvanced.html"
*
*/

#pragma once

#include "vtkBloomPassDll.h"

#include <vtkImageProcessingPass.h>
#include <vtkSmartPointer.h>

#define NO_BUFFERS	4

class VTK_BLOOM_PASS_EXPORT vtkBloomPass : public vtkImageProcessingPass
{
public:
	static vtkBloomPass *New();
	vtkTypeMacro(vtkBloomPass, vtkImageProcessingPass);
	void PrintSelf(ostream& os, vtkIndent indent);

	//BTX
	virtual void PreRender(const vtkRenderState* RenderState);
	virtual void Render(const vtkRenderState* RenderState);
	void ReleaseGraphicsResources(vtkWindow* Window);
	//ETX

	vtkGetMacro(Sensitivity, float);
	void SetSensitivity(float Sensitivity);

	vtkGetMacro(Intensity, float);
	void SetIntensity(float Intensity);

	vtkGetVector3Macro(FilterColor, float);
	void SetFilterColor(float Red, float Green, float Blue);

	vtkGetMacro(Enabled, bool);
	vtkSetMacro(Enabled, bool);

protected:
	vtkBloomPass();
	virtual ~vtkBloomPass();

	//BTX
	vtkSmartPointer<vtkFrameBufferObject>	SceneFBO;						// TODO: Write description
	vtkSmartPointer<vtkFrameBufferObject>	OffScreenFboL[NO_BUFFERS];		// TODO: Write description
	vtkSmartPointer<vtkFrameBufferObject>	OffScreenFboR[NO_BUFFERS];		// TODO: Write description
	vtkSmartPointer<vtkTextureObject>		SceneTexture;					// TODO: Write description
	vtkSmartPointer<vtkTextureObject>		OffScreenTextureL[NO_BUFFERS];	// TODO: Write description
	vtkSmartPointer<vtkTextureObject>		OffScreenTextureR[NO_BUFFERS];	// TODO: Write description
	vtkSmartPointer<vtkShaderProgram2>		BloomShader;					// TODO: Write description
	vtkSmartPointer<vtkShaderProgram2>		FilterShader;					// TODO: Write description
	vtkSmartPointer<vtkShaderProgram2>		BlitShader;						// TODO: Write description
	float									Sensitivity;					// TODO: Write description
	float									Intensity;						// TODO: Write description
	float									FilterColor[3];					// TODO: Write description
	int										WindowSize[2];					// TODO: Write description
	bool									Supported;						// TODO: Write description
	bool									SupportChecked;					// TODO: Write description
	bool									Enabled;						// TODO: Write description
	//ETX

private:
	vtkBloomPass(const vtkBloomPass&);		// Not implemented
	void operator=(const vtkBloomPass&);	// Not implemented

	void CreateBloomShader();
	void CreateFilterShader();
	void CreateBlitShader();

	bool IsSupported(const vtkRenderState* RenderState);
};
